package org.example.pdd;

import java.util.Stack;

/**
 * @author: lynn
 * @Descript:
 * @date: 2021/8/1 21:06
 * @version: 1.0
 */
public class Brackets {

    public static void main(String[] args) {
        String s=")(()";
        Stack<Character> stack =new Stack<>();
        int count=0;

        for (int i = 0; i < s.length() ; i++) {
            if (s.charAt(i)=='('){
                stack.push(s.charAt(i));
            }else {
                if (stack.size()>0 && s.charAt(i)==')' && stack.peek()=='('){
                    stack.pop();
                    count=count+2;
                }
            }
        }
        System.out.println(count);
    }
}
